package com.yuyang.gulimall.product.web;

import com.yuyang.gulimall.product.entity.CategoryEntity;
import com.yuyang.gulimall.product.service.CategoryService;
import com.yuyang.gulimall.product.vo.Catelog2Vo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * @author yu yang
 * @date 2023/1/8 -19:35
 */
@Controller
public class IndexController {
    @Autowired
    CategoryService categoryService;
    @GetMapping(value = {"/","/index.html"})
    public String index(Model model){
        //一级分类
        List<CategoryEntity> categoryEntities =categoryService.getCatelogLevelOne();
        model.addAttribute("categoryEntities",categoryEntities);
        return "index";
    }
    @ResponseBody
    @GetMapping("index/catalog.json")
    public Map<String, List<Catelog2Vo>> getCatelogLevelTwo(){
        Map<String, List<Catelog2Vo>> catelog2Vos = categoryService.getCatelogLevelTwo();
        return catelog2Vos;
    }

    @ResponseBody
    @GetMapping("/hello")
    public String hello(){
        return "hello";
    }
}
